package com.misakyanls.examples.random;

import java.util.HashSet;
import java.util.List;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.TypeSafeMatcher;

public class UniqueCollectionMatcher extends TypeSafeMatcher<List<Integer>> {

	@Override
	public void describeTo(Description description) {
		description.appendText("a collection containing only unique values");
	}

	@Override
	public boolean matchesSafely(List<Integer> list) {
		HashSet<Integer> uniques = new HashSet<Integer>();
		for (Integer item : list) {
			if (uniques.contains(item))
				return false;
			uniques.add(item);
		}
		return true;
	}
	
	@Factory
	public static UniqueCollectionMatcher containsOnlyUniques() {
        return new UniqueCollectionMatcher();
    }

}
